using Aurora.Discovery.HttpClient.Abstractions;
using Discovery.HttpClient.Consul.Options;
using Microsoft.Extensions.DependencyInjection;
using Nacos.AspNetCore.V2;

// using Nacos.AspNetCore.V2;

// using Nacos.AspNetCore.V2;

namespace Aurora.Discovery.HttpClient.Nacos;

public class NacosDiscoveryOptionsExtension : IDiscoveryOptionsExtension
{
    private readonly Action<NacosDiscoveryOptions> _configure;

    public NacosDiscoveryOptionsExtension(Action<NacosDiscoveryOptions> configure)
    {
        _configure = configure;
    }

    public void AddServices(IServiceCollection services)
    {
     
        NacosDiscoveryOptions options = new NacosDiscoveryOptions();
        _configure(options);
        services.Configure(_configure);

        services.AddNacosAspNet(x =>
        {
            x.ServiceName = options.ServiceName;
            x.ServerAddresses = options.ServerAddresses;
            x.Namespace = options.Namespace;
            x.GroupName = options.GroupName;
            x.ListenInterval = 1000;
        });
        services.AddSingleton<IDiscoveryClient, NacosDiscoveryClient>();
    }
}